package com.woniu.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniu.entity.SpenCategory;
import com.woniu.mapper.SpenCategoryMapper;
import com.woniu.service.ISpenCategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author hyl,fzn
 * @since 2022-08-28
 * todo 可优化判断
 */
@Transactional(rollbackFor = Exception.class)
@Service
@Slf4j
public class SpenCategoryServiceImpl extends ServiceImpl<SpenCategoryMapper, SpenCategory> implements ISpenCategoryService {
    @Autowired
    private SpenCategoryMapper scm;

    @Override
    public void addSpenCategory(SpenCategory sc) {
        if (sc.getCateId()!=null && sc.getCateId()>0
                && sc.getCateName()!=null && sc.getCateName()!=""
        ) {
            scm.addSpenCategory(sc);
        }
    }

    @Override
    public void updateSpenCategory(SpenCategory sc) {
        if (sc.getCateId()!=null && sc.getCateId()>0
                && sc.getCateName()!=null && sc.getCateName()!=""
        ) {
            scm.updateSpenCategory(sc);
        }
    }

    @Override
    public SpenCategory selectOneByCateId(Integer cateId) {
        if (cateId!=null && cateId>0) {
            return scm.selectOneByCateId(cateId);
        }else{
            log.debug("result:{}","传入的数据不符合约定，请检查");
            return null;
        }
    }

    @Override
    public SpenCategory selectOneByCateName(String cateName) {
        if(cateName!=null && cateName!="") {
            return scm.selectOneByCateName(cateName);
        }else{
            log.debug("result:{}","传入的数据不符合约定，请检查");
            return null;
        }
    }

    @Override
    public void deleteOne(Integer id) {
        if (id!=null && id>0) {
            scm.deleteOne(id);
        }
        }
}
